package com.ruoyi.common.DataConversion;

import com.ruoyi.common.domin.TypeConvertUtils;
import struct.StructClass;
import struct.StructField;

/**
 * @ClassName DownReadParam
 * @Description 读参数下行包 2024-10-06
 * @Author 张永永
 * @Date 2024-10-06
 * @Version 1.0.0.0
 **/
@StructClass
public class DownReadParamPackage {
    /**
     * 唯一码
     */
    @StructField(order = 0)
    public byte[] uniqueCode = new byte[2];

    /**
     * 地址
     */
    @StructField(order = 1)
    public byte[] address=new byte[2];

    /**
     * 数据长度
     */
    @StructField(order = 2)
    public byte[] dataLength = new byte[2];


    /**
     * 设置唯一码
     * @param uniqueCode
     */
    public void setUniqueCode(String uniqueCode) {
        this.uniqueCode = TypeConvertUtils.stringToBytes(uniqueCode);
    }

    /**
     * 设置写入地址
     * @param address
     */
    public void setAddress(String address) {
        //将地址码补齐为4位，并且反转
        String addressReverse= TypeConvertUtils.polishAndReverse(address,4);
        this.address = TypeConvertUtils.stringToBytes(addressReverse);
    }

    /**
     * 设置读取数据长度
     */
    public void setDataLength(int dataLengthTemp){
        this.dataLength=TypeConvertUtils.intToConverseBytes(dataLengthTemp,2);
    }
}
